package com.lglbc.day02;

import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 乐哥聊编程
 * @Doc 关注公众号"乐哥聊编程"获取文档和源码
 * @Date 2023/4/7
 * @Description
 */
@Controller
public class IndexController {
    @RequestMapping("/")
    @ResponseBody
    public String index(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return JSON.toJSONString(authentication);
    }
    @RequestMapping("/authentication")
    @ResponseBody
    public String index(Authentication authentication){
        return JSON.toJSONString(authentication);
    }
    @RequestMapping("/async")
    @ResponseBody
    public String async(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                System.out.println(JSON.toJSON(authentication));
            }
        }).start();
        return JSON.toJSONString("success");
    }

    @RequestMapping("/loginFail")
    public String loginFail(){
        return "login";
    }
}
